package com.ChenYaRou.www.controller.servlet;

import com.ChenYaRou.www.controller.HomePageServletController;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @ClassName TheHomePageServlet
 * @Description TODO
 * @Author 86183
 * @Date 2022/5/12 23:13
 * @Version 1.0
 **/
@MultipartConfig
public class TheHomePageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");
        try {
            Method method = HomePageServletController.class.getMethod(action, HttpServletRequest.class, HttpServletResponse.class);
            method.invoke(HomePageServletController.class.newInstance(),req,resp);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
